package com.syslog;



import java.util.HashMap;



import javax.servlet.http.HttpServletRequest;

import com.util.Component;
import com.PublicSystem;
import com.util.Util;


public class SysLogServices {
	private static final SysLogServices instance = new SysLogServices();
	 PublicSystem sys=PublicSystem.getInstance();
	 GetMac mac=GetMac.getInstance();

	 	private SysLogServices ()
		{	
			
		}
		public static SysLogServices getInstance ()
		{
			return instance;
		}
	 /**
	  * 日志系统核心方法(MAP方式)
	  * @param obj 需要传递以下参数：
	  * (DOMAINID分系统标识，LOG_TYPE日志类型，
	  * USERID操作人，RWH任务号，CONTENT操作明细,CZQD操作渠道,CZRLB操作人类别,DATAIN输入信息,DATAOUT输出信息)
	  * @param request
	  * @throws Exception
	  */
	 public void sysLogMap(HashMap obj,HttpServletRequest request) throws Exception
	 {
		
		 Sys_log vo=new Sys_log();
		
		 vo=(Sys_log)Util.MapToVo(vo, obj);
		
		 vo.setID(sys.getId("seq_sys_log"));
		 vo.setIP_ADDRESS(request.getRemoteAddr());
	     vo.setOPEN_TIME(Component.systime_all());
		 vo.setSESSIONID(request.getRequestedSessionId());
		
		 vo.setMAC_ADDRESS("");
		 System.out.println(request.getHeader("User-Agent"));
		 UserAgent userAgent = GetUserAgent.getUserAgent(request.getHeader("User-Agent"));  
		 String opsys=userAgent.getPlatformType()+"  "+userAgent.getPlatformSeries()+" / "+
		 userAgent.getBrowserType()+"  "+userAgent.getBrowserVersion();
		 vo.setBROWSER(opsys);
		 sys.Jdbc_saveDao(vo);
		 
		 
	 }
	 
	 /**
	  * 日志系统核心方法(字符串方式XXX#XXX#XXX...)
	  * (DOMAINID分系统标识，LOG_TYPE日志类型，
	  * USERID操作人，RWH任务号，CONTENT操作明细,CZQD操作渠道,CZRLB操作人类别,DATAIN输入信息,DATAOUT输出信息)
	  * @param request
	  * @throws Exception
	  */
	 public void sysLogStr(String obj,HttpServletRequest request) throws Exception
	 {
		
		 Sys_log vo=new Sys_log();
		 String res[]=obj.split("#");
		 
		 vo.setDOMAINID(res[0]);
		 vo.setLOG_TYPE(res[1]);
		 vo.setUSERID(res[2]);
		 vo.setRWH(res[3]);
		 vo.setCONTENT(res[4]);
		 vo.setCZQD(res[5]);
		 vo.setCZRLB(res[6]);
		 vo.setDATAIN(res[7]);
		 vo.setDATAOUT(res[8]);
		 
	
		 vo.setID(sys.getId("seq_sys_log"));
		 vo.setIP_ADDRESS(request.getRemoteAddr());
	     vo.setOPEN_TIME(Component.systime_all());
		 vo.setSESSIONID(request.getRequestedSessionId());
		
		 vo.setMAC_ADDRESS("");
		
		 UserAgent userAgent = GetUserAgent.getUserAgent(request.getHeader("User-Agent"));  
		 String opsys=userAgent.getPlatformType()+"  "+userAgent.getPlatformSeries()+" / "+
		 userAgent.getBrowserType()+"  "+userAgent.getBrowserVersion();
		 vo.setBROWSER(opsys);
		 sys.Jdbc_saveDao(vo);
		 
		 
	 }
	 
	
}
